package org.jie.guider.maven.codeformatter.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Objects;

/**
 * @author LiJie
 */
public class FileUtil {

    public static String fileRead(InputStream in) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder sb = new StringBuilder();
        String line;
        while (Objects.nonNull(line = reader.readLine())) {
            sb.append(line);
        }
        return sb.toString();
    }

    public static void fileWrite(String code, String targetFile)
        throws IOException {

        OutputStream out = new FileOutputStream(new File(targetFile));
        out.write(code.getBytes());
        out.flush();
        out.close();
    }
}
